<?php
$myFile = "data.txt";

if(!file_exists($myFile)){
	echo 'Error!';
}

$content = '';

$file_handle = fopen($myFile, "r");
while (!feof($file_handle)) {
   $line = fgets($file_handle);
   $string = trim($line);
   $pattern = '/(\s+)/i';
   $replacement = "\t";
   $content .= preg_replace($pattern, $replacement, $string)."\n";
}
fclose($file_handle);

header('Content-type: application/msword');
echo $content;